<template>
	<view class="">
		<!-- 会员授权 -->
		<!-- <u-popup :show="show" @close="close" @open="open">
			<view class="content">
				<view class="flex-column justify-center align-center">
					<image src="/static/img/n1.png" style="width: 300rpx;height: 250rpx;" mode="widthFix"></image>
					<view class="size mt-30">
						申请获得以下权限
					</view>
					<view class="mt-10 small-size gray-color">
						获得你的公开信息（手机号码）
					</view>
					<view class="" style="margin-top: 150rpx;"></view>
					<u-button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" text="手机号快捷登录" shape="circle"
						:customStyle="{'width':'80%'}"
						:color="$u.color.color"></u-button>
					<view @click="close" class="mt-30 small-size mt-30 gray-color">
						暂不授权
					</view>
				</view>
			</view>
		</u-popup> -->
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		getOpenid,
		getUserMobile
	} from '@/common/api.js'
	import {
		baseUrl
	} from '@/common/config.js'
	import {
		mapState
	} from "vuex";
	export default {
		props: {
			// show: {
			// 	type: Boolean,
			// 	default: false
			// },
		},
		watch: {
			show(e1, e2) {
				console.log('show', e1);
				this.$refs.uToast.show({
					type: 'error',
					message: '未登录',
					complete() {
						uni.reLaunch({
							url: '/pages/common/login'
						})
					}
				})
			},
		},
		data() {
			return {
				show: false,
				userInfo: {
					'nickname': "",
					'avatar': ""
				}
			}
		},
		computed: {
			...mapState(["isLogin"]),
		},
		methods: {
			jump() {
				uni.switchTab({
					url: '/pages/home/home'
				})
			},
			open() {},
			close() {
				this.show = false
			},
			getPhoneNumber(e) {
				let vm = this;
				uni.login({
					provider: 'weixin',
					success: async (res) => {
						console.log('code', res);
						getOpenid({
							data: {
								code: res.code
							}
						}).then(res => {
							console.log(res);
							let params = {
								iv: e.detail.iv,
								encryptedData: e.detail.encryptedData,
								sessionKey: res.session_key,
								openid: res.openid
							}

							getUserMobile(params).then(res => {
								console.log(res);
								uni.hideLoading();
								vm.$refs.uToast.show({
									type: 'success',
									message: '授权成功',
									complete() {
										uni.hideLoading()
										console.log('res', res);
										vm.$store.commit("setUserInfo", res.userinfo);
										vm.show = false;
										uni.reLaunch({
											url: '/pages/home/home'
										})
									}
								})
							})
						})
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		height: 500rpx;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-between;
	}

	.box-img {
		border: none;
		background-color: transparent;
	}

	.box-img::after {
		content: ' ';
		width: 0%;
		height: 0%;
		border: none;
	}
</style>